package com.boat.framework.common.monitor.event;

import java.net.URL;

import com.boat.framework.common.util.ServletUtils;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

/**
 * 二方系统调用出错
 * 
 * 羽嘉框架已自动埋点，业务系统无需开发
 * 
 * @author 周江
 *
 */
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
public class FeignCallFailed extends BaseMonitorEvent {

	/**
	 * 依赖系统名
	 */
	private String secName;
	/**
	 * 错误链接
	 */
	private String path;
	/**
	 * http调用状态码
	 */
	private Integer status;
	/**
	 * 耗时,单位毫秒
	 */
	private long times;
	/**
	 * 请求的controller地址
	 */
	private String requestUri;
	/**
	 * 备注
	 */
	private String remark;

	public FeignCallFailed() {
		super();
	}

	public FeignCallFailed(String urlStr, long times, Integer status) {
		super();
		setName(urlStr);
		
		try {
			URL url = new URL(urlStr);
			setSecName(url.getHost());
			setPath(urlStr);
			if (ServletUtils.getRequest() != null) {
				setRequestUri(ServletUtils.getRequest().getRequestURI());
			}
		} catch (Exception ex) {}
		setTimes(times);
		setStatus(status);
		setRemark("二方系统调用出错");
	}
}
